//
//  YTNewFlashViewModel.m
//  yitaicaijing
//
//  Created by DIANGHONG on 2018/7/21.
//  Copyright © 2018年 DIANGHONG. All rights reserved.
//

#import "YTNewFlashViewModel.h"

@interface YTNewFlashViewModel()

@property(nonatomic ,assign)int page;

@end

@implementation YTNewFlashViewModel

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.page = 1;
    }
    return self;
}

- (void)loadNewFlashListWithPullup:(BOOL)pullup
                        completion:(void(^)(BOOL isSucc, BOOL shouldReflash))completion
{
   
    if (pullup) {
        self.page++;
        
        if (self.page > self.model.total_pages.intValue) {
            completion(YES,false);
            return;
        }
    }else{
        
        self.page = 1;
    }
   
    [YTNetworkManager.shareManager requestMainNewFlashWithPage:self.page
                                                        page_size:@"10"
                                                       mintime:pullup ? self.model.list.lives.lastObject.post_date : nil
                                                  completion:^(id json, BOOL isSucc)
    {
        if (!isSucc) {
            completion(isSucc,NO);
            return ;
        }
        
        YTNewListsModel *model = [YTNewListsModel yy_modelWithJSON:json[@"data"]];
        
        if (!pullup) {
            self.model = model;
            completion(YES,YES);
        }else{
            self.model.list.lives = [self.model.list.lives arrayByAddingObjectsFromArray:model.list.lives];
            completion(YES,YES);
        }

    }];
}

@end
